package com.ccx.coachsite.ui.own;

import java.util.List;

import com.ccx.coachsite.R;
import com.ccx.coachsite.bus.UserInfo;
import android.content.Context;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View;
import android.view.View.OnCreateContextMenuListener;
import android.widget.AdapterView;
import android.widget.GridView;

public class OwerFriendView extends OwerBaseView implements OnCreateContextMenuListener{

	private GridView mFriendGrid;
	private OwerFriendGridAdapter mAdapter;
	private List<UserInfo> mApp;
	
	public OwerFriendView(Context context, OwerMainBase superView) {	
		super(context, superView);
		loadData();
	}
	
	private class OnItemClickListener implements android.widget.AdapterView.OnItemClickListener{
		@Override
		public void onItemClick(AdapterView<?> adapter, View v, int pos, long arg3) {
			if(pos < mApp.size())
			{
				SwitchView(OwerViewKey.ll_personal_friend_detail, mApp.get(pos));
				//OwerMainView mainView = (OwerMainView)mSuperView;
				//mainView.SwitchFriendDetail(OwerViewKey.ll_personal_friend_detail, mApp.get(pos));
			}
		}
	}
	
	protected boolean onLoadData() 
	{
		mApp = OwerProvider.getInstance().getFriendList(mContext);
		if (mApp == null)
			return false;
		return true;
	}
	
	protected void doRefreshDataSuccess()
	{
		mFriendGrid = (GridView) findViewById(R.id.ower_friend_grid);
		mFriendGrid.setOnCreateContextMenuListener(this);
		mFriendGrid.setOnItemClickListener(new OnItemClickListener());
		
		mAdapter = new OwerFriendGridAdapter(mContext, mApp);
		mFriendGrid.setAdapter(mAdapter);
	}

	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenuInfo menuInfo) {
		
		
	}
}
